package com.vlin.scene.actuator.defaut;

import java.util.ArrayList;
import java.util.List;

import com.vlin.entity.scene.Automation;
import com.vlin.entity.scene.Scene;
import com.vlin.entity.scene.TimerEvent;
import com.vlin.scene.actuator.AbstractSceneResolver;
import com.vlin.scene.actuator.ListSceneResolver;
import com.vlin.scene.actuator.SceneResolver;

public class DefaultListSceneResolver extends AbstractSceneResolver implements ListSceneResolver {

	
	private final List<SceneResolver> list = new ArrayList<>();
	
	@Override
	public void addSceneResolver(SceneResolver sceneResolver) {
		if(sceneResolver != null)
			this.list.add(sceneResolver);
	}

	@Override
	public boolean doSupport(Scene scene) {

		for(SceneResolver sceneResolver : list) {
			if(sceneResolver.support(scene)) {
				return true;
			}
		}
		
		return false;
	}

	@Override
	public TimerEvent doResolve(Scene scene) {
		for(SceneResolver sceneResolver : list) {
			if(sceneResolver.support(scene)) {
				return sceneResolver.resolve(scene);
			}
		}
		return null;
	}

	@Override
	public boolean doSupport(Automation automation) {
		for(SceneResolver sceneResolver : list) {
			if(sceneResolver.support(automation)) {
				return true;
			}
		}
		
		return false;
	}

	@Override
	public TimerEvent doResolve(Automation automation) {
		for(SceneResolver sceneResolver : list) {
			if(sceneResolver.support(automation)) {
				return sceneResolver.resolve(automation);
			}
		}
		return null;
	}

}
